package com.zxh.controller;

import com.zxh.pojo.Account;
import com.zxh.pojo.TransferInfo;
import com.zxh.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;
    
    //查找所用的用户
    @RequestMapping("/findAll")
    /*public String findAll(){
        System.out.println("表现层-->查询所有的用户");
        return "success";
    }*/
    public ModelAndView findAll(){
        System.out.println("表现层-->查询所有的用户");
        List<Account> accounts= accountService.findAll();
        //创建ModelAndView
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accounts",accounts);
        modelAndView.setViewName("success");
        return modelAndView;

    }

    //转账
    @RequestMapping("/transfer")
    public String transfer(TransferInfo transferInfo){
        System.out.println("控制层"+transferInfo);
        accountService.transfer(transferInfo);
        return "success";
    }
}
